package com.ce.cases.assit.logic.search;


import java.sql.ResultSet;
import java.sql.SQLException;

import com.ce.cases.assit.view.CaseInvestigationView;
import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.DateUtil;
import com.ce.framework.util.StringUtil;

/**
 * Created by 钢背猪☣ on 2017-8-7 0007.
 *
 * @ClassName: com.ce.cases.assit.logic.search
 * @Description: 描述:474752515@qq.com 功能描述：协查案源台账 [CASE_INVESTIGATION]条件过滤类
 * @author: 钢背猪☣
 * @date: 2017-8-7 0007
 */
public class CaseInvestigationSearchCondition  extends SQLSearchCondition
        implements ISQLMapper
{

    private String assitType;
    private String inspectDept;
    private String collectDept;
    private String involvedEnt;
    private String entrustDept;
    private String regBeginDate;
    private String regEndDate;
    private String isCc;
    private String isNormal;

    public String getSearchSql() throws AppException {

        StringBuffer sql = new StringBuffer("select * from CASE_INVESTIGATION t where t.VC_DEL$FLAG = 0");
        if(StringUtil.isNotBlank(assitType)){
            sql.append(" and t.assit_type_num=${assitType}");
        }
        if(StringUtil.isNotBlank(inspectDept)){
            sql.append(" and t.inspection_dept_id=${inspectDept}");
        }
        if(StringUtil.isNotBlank(collectDept)){
            sql.append(" and t.collection_dept_id=${collectDept}");
        }
        if(StringUtil.isNotBlank(isCc)){
            sql.append(" and t.IS_CC=${isCc}");
        }
        if(StringUtil.isNotBlank(isNormal)){
            sql.append(" and t.IS_NORMAL=${isNormal}");
        }

        if(StringUtil.isNotBlank(involvedEnt)){
            sql.append(" and t.involved_enterprice like '%'||${involvedEnt}||'%'");
        }
        if(StringUtil.isNotBlank(entrustDept)){
            sql.append(" and t.ENTRUST_DEPT like '%'||${entrustDept}||'%'");
        }
		/*
		 * 2015-06-09 by 刘渝洪，开始
		 * 修改搜索处理
		 * 默认初始列表时，或搜索日期条件没值时，搜索出的结果为：本年度的数据
		 * 设置搜索日期条件时，搜索出的结果为：满足日期条件的数据
		 * 原代码：
		 * sql.append(this.getDateCondition("register_date", regBeginDate, regEndDate));
		 * 修改后代码：
		 */
        if (StringUtil.isNotBlank(regBeginDate)
                || StringUtil.isNotBlank(regEndDate)) {
            sql.append(this.getDateCondition("register_date", regBeginDate, regEndDate));
        } else {
            String dateBeginOfThisYear = DateUtil.getYear() + "-01-01 00:00:00";
            String dateEndOfThisYear = DateUtil.getYear() + "-12-31 23:59:59";
            sql.append(" and ").append("register_date").append(">=to_date('")
                    .append(dateBeginOfThisYear)
                    .append("','yyyy-mm-dd hh24:mi:ss') ");
            sql.append(" and ").append("register_date").append("<=to_date('")
                    .append(dateEndOfThisYear)
                    .append("','yyyy-mm-dd hh24:mi:ss') ");
        }
		/* 2015-06-09 by 刘渝洪，结束 */
        //排序
        if(StringUtil.isNotBlank(this.order)){
            sql.append(" order by "+ this.getOrderByUnderLine());
        }else{
            sql.append(" order by register_date desc");
        }
        return sql.toString();
    }

    public Object fromSQLQuery(ResultSet rs, int num) {
        CaseInvestigationView view = new CaseInvestigationView();
        try {

            view.setVcId(rs.getString("VC_ID"));
            view.setCaseNumber(rs.getString("CASE_NUMBER"));
            view.setRegisterPerson(rs.getString("REGISTER_PERSON"));
            view.setRegisterDeptId(rs.getString("REGISTER_DEPT_ID"));
            view.setRegisterDept(rs.getString("REGISTER_DEPT"));
            view.setRegisterDate(rs.getDate("REGISTER_DATE"));
            view.setTaxpayerNumber(rs.getString("TAXPAYER_NUMBER"));
            view.setInvolvedEnterprice(rs.getString("INVOLVED_ENTERPRICE"));
            view.setInspectionDeptId(rs.getString("INSPECTION_DEPT_ID"));
            view.setInspectionDept(rs.getString("INSPECTION_DEPT"));
            view.setCollectionDeptId(rs.getString("COLLECTION_DEPT_ID"));
            view.setCollectionDept(rs.getString("COLLECTION_DEPT"));
            view.setAssitTypeNum(rs.getString("ASSIT_TYPE_NUM"));
            view.setAssitTypeName(rs.getString("ASSIT_TYPE_NAME"));
            view.setAssitItem(rs.getString("ASSIT_ITEM"));
            view.setIsCity(rs.getInt("IS_CITY"));
            view.setIsCc(rs.getInt("IS_CC"));
            view.setProblemBill(rs.getInt("PROBLEM_BILL"));
            view.setEntrustCode(rs.getString("ENTRUST_CODE"));
            view.setEntrustDept(rs.getString("ENTRUST_DEPT"));
            view.setBillCount(rs.getInt("BILL_COUNT"));
            view.setAmountMoney(rs.getDouble("AMOUNT_MONEY"));
            view.setTaxMoney(rs.getDouble("TAX_MONEY"));
            view.setNoVerify(rs.getInt("NO_VERIFY"));
            view.setIsNormal(rs.getInt("IS_NORMAL"));
            view.setIsImportant(rs.getInt("IS_IMPORTANT"));
            view.setIsSecret(rs.getInt("IS_SECRET"));
            view.setCaseFromNum(rs.getString("CASE_FROM_NUM"));
            view.setCaseFromName(rs.getString("CASE_FROM_NAME"));
            view.setBaseResult(rs.getString("BASE_RESULT"));
            view.setAssitReason(rs.getString("ASSIT_REASON"));
            view.setFileId(rs.getString("FILE_ID"));
            view.setReplyPersonId(rs.getString("REPLY_PERSON_ID"));
            view.setReplyPersonName(rs.getString("REPLY_PERSON_NAME"));
            view.setReplyDate(rs.getDate("REPLY_DATE"));
            view.setCheckTypeNum(rs.getString("CHECK_TYPE_NUM"));
            view.setCheckTypeName(rs.getString("CHECK_TYPE_NAME"));
            view.setState(rs.getInt("STATE"));
            view.setVcNote(rs.getString("VC_NOTE"));
            view.setVcDelFlag(rs.getInt("VC_DEL$FLAG"));

        } catch (SQLException e) {

            e.printStackTrace();
        }
        return view;
    }

    public ISQLMapper getSQLMapper() {

        return this;
    }

    public String getAssitType() {
        return assitType;
    }

    public void setAssitType(String assitType) {
        this.assitType = assitType;
    }

    public String getInspectDept() {
        return inspectDept;
    }

    public void setInspectDept(String inspectDept) {
        this.inspectDept = inspectDept;
    }

    public String getCollectDept() {
        return collectDept;
    }

    public void setCollectDept(String collectDept) {
        this.collectDept = collectDept;
    }

    public String getInvolvedEnt() {
        return involvedEnt;
    }

    public void setInvolvedEnt(String involvedEnt) {
        this.involvedEnt = involvedEnt;
    }

    public String getRegBeginDate() {
        return regBeginDate;
    }

    public void setRegBeginDate(String regBeginDate) {
        this.regBeginDate = regBeginDate;
    }

    public String getRegEndDate() {
        return regEndDate;
    }

    public void setRegEndDate(String regEndDate) {
        this.regEndDate = regEndDate;
    }

    public String getEntrustDept() {
        return entrustDept;
    }

    public void setEntrustDept(String entrustDept) {
        this.entrustDept = entrustDept;
    }

    public String getIsCc() {
        return isCc;
    }

    public void setIsCc(String isCc) {
        this.isCc = isCc;
    }

    public String getIsNormal() {
        return isNormal;
    }

    public void setIsNormal(String isNormal) {
        this.isNormal = isNormal;
    }



}
